<?
include("lib/config.php");
/* 
	catatan:
	direktorat			level 1		2 digit
	koordiantor			level 2		2 digit
	cabang/divisi/biro	level 3		3 digit
	bagian				level 4		3 digit
	seksi				level 5		2 digit
	
	000000000000
	123456789123 mssql
	012345678900 php
	
*/

// get direktorat
	$sql1 = mssql_query("select * from vleveldirektorat order by kode_so",$conn);
	while($row1 = mssql_fetch_array($sql1)){
		echo "direktorat<br>";
		echo"$row1[kode_so] - $row1[uraian]<br>";
		// get koordinator
		$sql2 = mssql_query("select * from vlevelkoordinator where substring(kode_so,1,2)='".substr($row1[kode_so],0,2)."' order by kode_so",$conn);
		echo"
		<blockquote>
		koordinator <br>";
		while($row2 = mssql_fetch_array($sql2)){
			echo"$row2[kode_so] - $row2[uraian]<br>";
			// get cabang/divisi/biro
			$sql3 = mssql_query("select * from vlevelcabang where substring(kode_so,1,2)='".substr($row1[kode_so],0,2)."' and substring(kode_so,3,2)='".substr($row2[kode_so],2,2)."' order by kode_so",$conn);
			echo"
			<blockquote><br>";
			while($row3 = mssql_fetch_array($sql3)){
				echo"cabang/biro/divisi<br>";
				echo"$row3[kode_so] - $row3[uraian]<br>";
				// get bagian
				$sql4 = mssql_query("select * from vlevelbagian where substring(kode_so,1,2)='".substr($row1[kode_so],0,2)."' and substring(kode_so,3,2)='".substr($row2[kode_so],2,2)."' and substring(kode_so,5,3)='".substr($row3[kode_so],4,3)."' order by kode_so",$conn);
				echo"<blockquote>bagian<br>";
				while($row4 = mssql_fetch_array($sql4)){
					echo"$row4[kode_so] - $row4[uraian]<br>";
					// get seksi
					$sql5 = mssql_query("select * from vlevelseksi where substring(kode_so,1,2)='".substr($row1[kode_so],0,2)."' and substring(kode_so,3,2)='".substr($row2[kode_so],2,2)."' and substring(kode_so,5,3)='".substr($row3[kode_so],4,3)."' and substring(kode_so,8,3)='".substr($row4[kode_so],7,3)."' order by kode_so",$conn);
					echo"<blockquote>seksi<br>";
					while($row5 = mssql_fetch_array($sql5)){
						echo"$row5[kode_so] - $row5[uraian]<br>";
					}
					echo"</blockquote>";
				}
				echo"</blockquote>";
			}
			echo"</blockquote>";
		}
		echo"</blockquote>";
	}
?>